package com.kaiyidiannao.model.req.model;

import android.util.Log;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.model.Result;
import com.kaiyidiannao.model.req.base.BaseCommand;
import org.json.JSONObject;

import java.util.HashMap;

/**
 *   凑对去 加关注 - 异步请求
 */
public class GetTourAddFocus extends BaseCommand {

    private int typeid; //当前分类编号
    private String userid =  DataCenter.userLogin.get(0).getUserid(); //用户id
    private String action = ""; //添加数据, add, delete
    private String TAG = "GetAddMessageInfo";
    private String itemid ;
    private String title;

    public GetTourAddFocus(int typeid) {
        this.typeid = typeid;
    }

    public GetTourAddFocus(int typeid, String userid) {
        this.typeid = typeid;
        this.userid = userid;
    }

    public GetTourAddFocus(int typeid, String userid, String action, String itemid) {
        this.typeid = typeid;
        this.userid = userid;
        this.action = action;
        this.itemid = itemid;
        this.title = "";
    }

    @Override
    public String getRequestUrl() {
        return DataCenter.POST_FAVORITES_ADDRESS;
    }

    @Override
    public HashMap<String, String> getRequestParamters() {
        HashMap<String, String> paramters = new HashMap<String, String>();
        paramters.put("typeid", typeid  + "");
        paramters.put("userid",userid + "");
        paramters.put("action",action + "");
        paramters.put("itemid",itemid + "");
        paramters.put("title",title);
        return paramters;
    }

    @Override
    public Result go(String url, HashMap<String, String> paramters) { // 联网时后台执行
        // 根据请求参数返回请求数据
        return HttpUtils.postByHttpClient(url, paramters);
    }

    @Override
    public void yes(Result result) { //后台执行完毕后执行
        super.yes(result);
        Log.d(DataCenter.LOG_INFO, "GetTourAddFocus.yes()");
        try {
            Log.d(TAG, result.object.toString());
            JSONObject jsonObject = new JSONObject(result.object.toString());
            String resultes= jsonObject.getString("msg");
            Log.d(TAG, resultes.toString());
            DataCenter.resultes = resultes.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        DataCenter.getInstance().callBacks(DataCenter.flag.GetAddMESSAGEINFO_SUCCESS);
    }

    @Override
    public void no(Result result) {
        super.no(result);
        Log.d(DataCenter.LOG_ERROR, "GetTourAddFocus.no()");
        DataCenter.getInstance().callBacks(DataCenter.flag.GetAddMESSAGEINFO_FAILED);
    }
}
